package com.gxa.web_admin.rabbitmq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 广播方式：
 *     自定义交换机+队列
 */
//@Configuration
public class FanoutConfig {

    /**
     * 声明交换机
     * @return
     */
    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange("gxa.fanout");
    }
    /**
     * 声明交换队列
     * @return
     */
    @Bean
    public Queue fanoutQueueOne(){
        return new Queue("fanout.queueone");
    }
    @Bean
    public Queue fanoutQueueTwo(){
        return new Queue("fanout.queuetwo");
    }
    /**
     * 绑定队列和交换机
     * @param fanoutExchange
     * @param fanoutQueueOne
     * @return
     */
    @Bean
    public Binding bindingQueueOne(FanoutExchange fanoutExchange,Queue fanoutQueueOne){
        return BindingBuilder.bind(fanoutQueueOne).to(fanoutExchange);
    }
    @Bean
    public Binding bindingQueueTwo(FanoutExchange fanoutExchange,Queue fanoutQueueTwo){
        return BindingBuilder.bind(fanoutQueueTwo).to(fanoutExchange);
    }
}
